package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Mr.Xi
 * Date: 2023-04-17
 * Time: 12:07
 */
@Configuration
public class AddCorsMappings implements WebMvcConfigurer {

    // SpringBoot 跨域配置
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 设置允许跨域的路径
        registry.addMapping("/**")
                // 设置允许跨域请求的域名
                .allowedOriginPatterns("*")
                // 是否允许 cookie
                .allowCredentials(true)
                // 设置允许的请求方式
                .allowedMethods("GET","POST","PUT","DELETE")
                // 设置允许的 header 属性
                .allowedHeaders("*")
                // 跨域允许的时间
                .maxAge(3600);
    }
}
